var e = i(require("../../libs/mini/create")), t = i(require("../../store/index")), a = (i(require("../../utils/storage")), 
require("../../api/user")), n = require("../../api/member");

function i(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

var o = getApp(), r = null;

e.default.Page(t.default, {
    use: [ "customLoading", "custom", "userInfo", "userInfo.role" ],
    data: {
        loading: !0,
        form: {}
    },
    onLoad: function(e) {
        var n = this, i = decodeURIComponent(e.scene || "");
        if (!((i = o.utils.queryString.parse(i)) && i.uid && i.role && i.percent)) return o.utils.modalText("小程序码出现未知参数，请联系管理员重新生成WiFi绑定码。").then(function() {
            o.utils.alwaysBack();
        });
        this.showLoading("数据加载中"), t.default.getUserInfo(function() {
            (0, a.getMemberInfoById)({
                uid: i.uid
            }).then(function(e) {
                var t = Object.assign({}, n.data.form, i);
                n.setData({
                    form: t,
                    memberInfo: e
                }), n.hideLoading();
            }).catch(function() {
                n.hideLoading(), o.utils.modalText("小程序码出现未知参数，请联系管理员重新生成WiFi绑定码。").then(function() {
                    o.utils.alwaysBack();
                });
            });
        });
    },
    onUnload: function() {
        r && (clearTimeout(r), r = null);
    },
    showLoading: function() {
        var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "", t = !(1 < arguments.length && void 0 !== arguments[1]) || arguments[1];
        this.setData({
            loading: !0
        }), wx.showLoading({
            title: e,
            mask: t
        });
    },
    hideLoading: function() {
        this.setData({
            loading: !1
        }), wx.hideLoading();
    },
    handleBannerItemClick: function(e) {
        var t = e.currentTarget.dataset.item;
        switch (t.type) {
          case "h5":
            t.url ? wx.navigateTo({
                url: "/pages/webview/index?src=" + t.url
            }) : o.utils.modalText("未设置跳转内容，操作失败");
            break;

          case "mini":
            wx.navigateToMiniProgram({
                appId: t.appid,
                path: decodeURIComponent(t.url),
                fail: function(e) {
                    "navigateToMiniProgram:fail invalid appid" === (e = e.errMsg) ? o.utils.modalText("跳转失败，可能是小程序路径或appid填写错误") : "navigateToMiniProgram:fail can't navigate to myself" === e && wx.navigateTo({
                        url: decodeURIComponent(t.url)
                    });
                }
            });
        }
    },
    onShowTip: function(e) {
        return "real_name" == (e = e.currentTarget.dataset.name) ? o.utils.modalText("请正确填写您的名字，该项主要用于佣金提现时的真实姓名校验。") : "mobile" == e ? o.utils.modalText("请正确填写您的手机号，该项主要用于佣金提现时的手机号校验，同时也方便代理商核实您的身份。") : void 0;
    },
    onInputChange: function(e) {
        var t = e.currentTarget.dataset.name;
        e = e.detail.value;
        this.setFormData(t, e);
    },
    setFormData: function(e, t) {
        this.setData(function(e, t, a) {
            return t in e ? Object.defineProperty(e, t, {
                value: a,
                enumerable: !0,
                configurable: !0,
                writable: !0
            }) : e[t] = a, e;
        }({}, "form." + e, t));
    },
    onClearClick: function(e) {
        e = e.currentTarget.dataset.name, this.setFormData(e, "");
    },
    handleCopy: function(e) {
        var t = e.currentTarget.dataset.content;
        return o.utils.modalText("是否复制该微信号？", "立即复制").then(function() {
            wx.setClipboardData({
                data: t
            });
        });
    },
    handleMobile: function(e) {
        e = e.currentTarget.dataset.content, wx.makePhoneCall({
            phoneNumber: e
        });
    },
    handleConfirm: function() {
        var e = this;
        if (!this.loading) {
            var t = this.data.$.userInfo, a = this.data.memberInfo;
            return (t = Object.assign({}, this.data.form, {
                openid: t.openid,
                nickname: t.nickname,
                avatar: t.avatar
            })).real_name ? t.mobile ? 11 !== t.mobile.length ? o.utils.toastText("请填写正确格式的手机号") : (t.pid = a.id, 
            t.popenid = a.openid, this.showLoading("正在申请"), void (0, n.addMemberInfo)(t).then(function() {
                e.hideLoading(), o.utils.modalText("您提交的资料已上传，审核通过后，重新刷新小程序，即可开始管理您的代理团队。", "立即刷新").then(function() {
                    wx.reLaunch({
                        url: "/pages/home/index"
                    });
                });
            }).catch(function() {
                e.hideLoading();
            })) : o.utils.toastText("请填写您的手机号") : o.utils.toastText("请填写您的真实姓名");
        }
    }
});